package com.stx.servlet.car;

import com.stx.bean.Car;
import com.stx.mapper.CarMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(urlPatterns = {"/carUpdate"})
public class CarUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String carNumber = req.getParameter("carNumber");
        String carOwner = req.getParameter("carOwner");
        String phone = req.getParameter("phone");
        Car car = new Car(id, carNumber, carOwner, phone);
        try {
            Boolean aBoolean = CarMapper.carUpdate(car);
            resp.sendRedirect("/carList");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

}
